package com.example.demo.Controller;

import lombok.Data;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.CSVRecord;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.List;

@Data
@EnableAutoConfiguration
public class RegionStats {
    private String state;
    private String country;
    private String latestTotalCases;
    private String diffFromPrevDay;

    @RequestMapping("/analyse")
    public void analyse() {
        try {
            System.out.println("123");
            Reader in = new FileReader("https://gitee.com/dgut-sai/COVID-19/raw/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv");
            Iterable<CSVRecord> records = CSVFormat.RFC4180.withHeader("Provice/State", "Country/Region", "Lat", "Long").parse(in);
            for (CSVRecord record : records) {
                state = record.get("Province/State");
                country = record.get("Country/Region");
                latestTotalCases = record.get("Lat");
                diffFromPrevDay = record.get("Long");
            }
            final Appendable out = null;
            final CSVPrinter printer = CSVFormat.DEFAULT.withHeader("State", "country", "Lat", "Long").print(out);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
